package com.sam.mvp.presenter;

import android.app.Application;

import com.jess.arms.integration.AppManager;
import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.mvp.BasePresenter;
import com.jess.arms.http.imageloader.ImageLoader;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import me.jessyan.rxerrorhandler.core.RxErrorHandler;

import javax.inject.Inject;

import com.sam.mvp.contract.HomeContract;
import com.sam.mvp.entity.HomeEnity;
import com.sam.mvp.ui.adapter.HomeAdapter;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;


@ActivityScope
public class HomePresenter extends BasePresenter<HomeContract.Model, HomeContract.View> {
    @Inject
    RxErrorHandler mErrorHandler;
    @Inject
    Application mApplication;
    @Inject
    ImageLoader mImageLoader;
    @Inject
    AppManager mAppManager;

    @Inject
    HomeAdapter mAdapter;


    @Inject
    public HomePresenter(HomeContract.Model model, HomeContract.View rootView) {
        super(model, rootView);
    }

    public void getData() {

        mAdapter.notifyLoading();

        Observable.just("")
                .delay(2, TimeUnit.SECONDS)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(s -> {
                    List<HomeEnity> list1 = new ArrayList<HomeEnity>();
                    List<HomeEnity> list2 = new ArrayList<HomeEnity>();
                    List<HomeEnity> list3 = new ArrayList<HomeEnity>();
                    for (int i = 0; i < 5; i++) {
                        list1.add(new HomeEnity("top : " + i, HomeEnity.TOP));
                        list1.add(new HomeEnity("top : " + i, HomeEnity.TOP));
                        list1.add(new HomeEnity("top : " + i, HomeEnity.TOP));
                        list2.add(new HomeEnity("center : " + i, HomeEnity.CENTER));
                        list3.add(new HomeEnity("bottom  : " + i, HomeEnity.BOTTOM));
                    }
                    mAdapter.notityDataAndHeadAndFooter(list1, HomeEnity.TOP_HEAD_TITLE, HomeEnity.TOP_FOOTER_TITLE, HomeEnity.TOP);
                    mAdapter.notifyDataAndHead(list2, HomeEnity.CENTER_HEAD_TITLE, HomeEnity.CENTER);
                    mAdapter.notifyDataAndHead(list3, HomeEnity.BOTTOM_HEAD_TITLE, HomeEnity.BOTTOM);
                });


    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mErrorHandler = null;
        this.mAppManager = null;
        this.mImageLoader = null;
        this.mApplication = null;
        this.mAdapter = null;
    }
}
